package ru.papergames.web.interceptors;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import ru.papergames.web.controllers.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * auth interceptor
 *
 * @author Alexander Troshanin
 */
public class AuthInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // here handler is our controller!!!
        return handler instanceof AbstractController && ((AbstractController) handler).checkAuth(request, response);
    }

}
